package com.zhongwang.business.module.estimateBudgetAccountingManage.controller;

import com.zhongwang.business.annotation.LogAnnotation;
import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.service.GetDataService;
import com.zhongwang.business.util.ShiroUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 徐一贺
 * @version 1.0
 * @exception: GetDataController
 * 数据获取测试控制层
 * @date 2020/9/11 15:04
 */
@Controller
@RequestMapping("/getData")
public class GetDataController extends BaseController {
    @Autowired
    private GetDataService getDataService;

    /**
     * page
     * 页面跳转
     *
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/9/11 15:07
     * @version 1.0
     */
    @GetMapping
    public String page() {
        return "dataTest/page";
    }

    /**
     * page
     * 页面跳转-核算-数据获取
     *
     * @param adtId 单据表主键
     * @param code  项目号
     * @param model 页面渲染模型
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/9/11 15:07
     * @version 1.0
     */
    @GetMapping("/accounting/{adtId}/{code}")
    @RequiresPermissions("ver:collec:view")
    public String accountingPage(@PathVariable("adtId") String adtId, @PathVariable("code") String code, Model model) {
//        getDataService.generateOrderData(code);
        ProjectModel project = getDataService.getProjectModel(code);
        model.addAttribute("project", project);
        model.addAttribute("batId", adtId);
        return "accountManage/getData/accounting";
    }

    /**
     * page
     * 页面跳转-核算-成本编辑
     *
     * @param adtId 单据表主键
     * @param code  项目号
     * @param model 页面渲染模型
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/9/11 15:07
     * @version 1.0
     */
    @RequiresPermissions("ver:adjust:view")
    @GetMapping("/accountingCostEdit/{adtId}/{code}")
    public String accountingCostEditPage(@PathVariable("adtId") String adtId, @PathVariable("code") String code, Model model) {
        model.addAttribute("batId", Integer.valueOf(adtId));
//        //成本清单
//        List<BusBudgetAccountingCostModel> busBudgetAccountingCosts = getDataService.findBusBudgetAccountingCostListByBatId(adtId, 5);
//        //基础参数数据
//        List<BusBudgetAccountingBasicInfoConfig> busBudgetAccountingBasicInfoConfigList = getDataService.findBusBudgetAccountingBasicInfoConfigByBatId(Integer.valueOf(adtId));
//        //获取核算设备总重
//        BigDecimal equipmentTotalWeight = getDataService.getAccountingEquipmentTotalWeightByBatId(Integer.valueOf(adtId));
//        //获取核算设备净重
//        BigDecimal equipmentTotalNetWeight = getDataService.getAccountingEquipmentTotalNetWeightByBatId(Integer.valueOf(adtId));
        ProjectModel project = getDataService.getProjectModel(code);
        model.addAttribute("project", project);
        model.addAttribute("batId", Integer.valueOf(adtId));
//        model.addAttribute("amountDisplayModel", busBudgetAccountingCosts.get(0).getAmountDisplayModel());
//        model.addAttribute("busBudgetAccountingCosts", busBudgetAccountingCosts);
//        model.addAttribute("busBudgetAccountingBasicInfoConfigList", busBudgetAccountingBasicInfoConfigList);
//        model.addAttribute("equipmentTotalWeight", equipmentTotalWeight);
//        model.addAttribute("equipmentTotalNetWeight", equipmentTotalNetWeight);
        return "accountManage/cost/edit/page";
    }

    /**
     * page
     * 取消保存并编辑页面跳转-核算-成本编辑
     *
     * @param adtId 单据表主键
     * @param code  项目号
     * @param model 页面渲染模型
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/9/11 15:07
     * @version 1.0
     */
    @RequiresPermissions("ver:submit:commit")
    @GetMapping("/accountingCostEditByCancelSave/{adtId}/{code}")
    public String accountingCostEditByCancelSave(@PathVariable("adtId") String adtId, @PathVariable("code") String code, Model model) {
        BusBudgetAccountingTaskModel task = getDataService.getBusBudgetAccountingTaskByPrimaryKey(Integer.valueOf(adtId));
        task.setIsSave(0);
        getDataService.updateBusBudgetAccountingTaskByPrimaryKey(task);
        //获取当前审批最后节点状态判断是不是驳回，如果是驳回把驳回意见渲染到页面当中
        AccountingProjectModel reject = getDataService.getRejectInfoBy(Integer.valueOf(adtId), ShiroUtils.getUserId());
        model.addAttribute("reject", reject);

        model.addAttribute("batId", Integer.valueOf(adtId));
        //成本清单
        List<BusBudgetAccountingCostModel> busBudgetAccountingCosts = getDataService.findBusBudgetAccountingCostListByBatId(adtId, 5);
        //基础参数数据
        List<BusBudgetAccountingBasicInfoConfig> busBudgetAccountingBasicInfoConfigList = getDataService.findBusBudgetAccountingBasicInfoConfigByBatId(Integer.valueOf(adtId));
        //获取核算设备总重
        BigDecimal equipmentTotalWeight = getDataService.getAccountingEquipmentTotalWeightByBatId(Integer.valueOf(adtId));
        //获取核算设备净重
        BigDecimal equipmentTotalNetWeight = getDataService.getAccountingEquipmentTotalNetWeightByBatId(Integer.valueOf(adtId));
        ProjectModel project = getDataService.getProjectModel(code);
        model.addAttribute("amountDisplayModel", busBudgetAccountingCosts.get(0).getAmountDisplayModel());
        model.addAttribute("project", project);
        model.addAttribute("busBudgetAccountingCosts", busBudgetAccountingCosts);
        model.addAttribute("busBudgetAccountingBasicInfoConfigList", busBudgetAccountingBasicInfoConfigList);
        model.addAttribute("equipmentTotalWeight", equipmentTotalWeight);
        model.addAttribute("equipmentTotalNetWeight", equipmentTotalNetWeight);
        return "accountManage/cost/edit/page";
    }
    /** page
     * 取消保存并编辑页面跳转-概算-成本编辑
     * @param adtId
     * @param code
     * @param model
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/8 10:03
     */
    @RequiresPermissions("rou:submit:commit")
    @GetMapping("/estimatingCostEditByCancelSave/{adtId}/{code}")
    public String estimatingCostEditByCancelSave(@PathVariable("adtId") String adtId, @PathVariable("code") String code, Model model) {
        BusBudgetAccountingTaskModel task = getDataService.getBusBudgetAccountingTaskByPrimaryKey(Integer.valueOf(adtId));
        task.setIsSave(0);
        getDataService.updateBusBudgetAccountingTaskByPrimaryKey(task);
        //获取当前审批最后节点状态判断是不是驳回，如果是驳回把驳回意见渲染到页面当中
        AccountingProjectModel reject = getDataService.getEstimatingRejectInfoBy(Integer.valueOf(adtId), ShiroUtils.getUserId());
        model.addAttribute("reject", reject);

        model.addAttribute("batId", Integer.valueOf(adtId));
        //成本清单
        List<BusBudgetAccountingCostModel> busBudgetAccountingCosts = getDataService.findBusBudgetAccountingCostListByBatId(adtId, 5);
        //基础参数数据
        List<BusBudgetAccountingBasicInfoConfig> busBudgetAccountingBasicInfoConfigList = getDataService.findBusBudgetAccountingBasicInfoConfigByBatId(Integer.valueOf(adtId));
        //获取概算设备总重
        BigDecimal equipmentTotalWeight = getDataService.getAccountingEquipmentTotalWeightByBatId(Integer.valueOf(adtId));
        //获取概算设备净重
        BigDecimal equipmentTotalNetWeight = getDataService.getAccountingEquipmentTotalNetWeightByBatId(Integer.valueOf(adtId));
        ProjectModel project = getDataService.getProjectModel(code);
        model.addAttribute("amountDisplayModel", busBudgetAccountingCosts.get(0).getAmountDisplayModel());
        model.addAttribute("project", project);
        model.addAttribute("busBudgetAccountingCosts", busBudgetAccountingCosts);
        model.addAttribute("busBudgetAccountingBasicInfoConfigList", busBudgetAccountingBasicInfoConfigList);
        model.addAttribute("equipmentTotalWeight", equipmentTotalWeight);
        model.addAttribute("equipmentTotalNetWeight", equipmentTotalNetWeight);
        return "estimateManage/editCostSheet/page";
    }


    /**
     * page
     * 页面跳转-核算-查看明细
     *
     * @param dsId  数据源主键
     * @param batId 单据表主键
     * @param code  项目号
     * @param model 页面渲染模型
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/9/11 15:07
     * @version 1.0
     */
    @GetMapping("/gotoViewPage/{dsId}/{batId}/{code}")
    @RequiresPermissions("ver:collection:view")
    public String gotoViewPage(@PathVariable("dsId") String dsId, @PathVariable("batId") String batId, @PathVariable("code") String code, Model model) {
        //如果没有单据表数据，则生成单据表表和对应的数据源表数据
        ProjectModel project = getDataService.getProjectModel(code);
        BusDataSource dataSource = getDataService.getDataSourceByPrimaryKey(Integer.valueOf(dsId));
        model.addAttribute("project", project);
        model.addAttribute("dataSource", dataSource);
        model.addAttribute("batId", batId);
        String title = "";
        String url = "";
        BusDataSource abDataSource = getDataService.getAbDataSourceByPrimaryKey(dsId);
        if ("ds001".equals(abDataSource.getDataCode())) {
            title = "设计工时重量";
            url = "accountManage/getData/designView";
        } else if ("ds002".equals(abDataSource.getDataCode())) {
            title = "外购件";
            url = "accountManage/getData/buyView";
        } else if ("ds003".equals(abDataSource.getDataCode())) {
            title = "原材料";
            url = "accountManage/getData/matView";
        } else if ("ds004".equals(abDataSource.getDataCode())) {
            title = "外协";
            url = "accountManage/getData/outView";
        }
//        else if ("ds005".equals(abDataSource.getDataCode())) {
//            title = "带料外协";
//            url = "accountManage/getData/outsWithMatView";
//        }
        else if ("ds006".equals(abDataSource.getDataCode())) {
            title = "下料";
            url = "accountManage/getData/cutView";
        } else if ("ds007".equals(abDataSource.getDataCode())) {
            title = "铆焊工时";
            url = "accountManage/getData/weldView";
        } else if ("ds008".equals(abDataSource.getDataCode())) {
            title = "机加工时";
            url = "accountManage/getData/macView";
        } else if ("ds009".equals(abDataSource.getDataCode())) {
            title = "热处理";
            url = "accountManage/getData/heatView";
        } else if ("ds010".equals(abDataSource.getDataCode())) {
            title = "涂装工时";
            url = "accountManage/getData/paintView";
        } else if ("ds011".equals(abDataSource.getDataCode())) {
            title = "装配工时";
            url = "accountManage/getData/assemblView";
        } else if ("ds012".equals(abDataSource.getDataCode())) {
            title = "包装、运输";
            url = "accountManage/getData/pacAndTranView";
        } else if ("ds013".equals(abDataSource.getDataCode())) {
            url = "accountManage/getData/installView";
            title = "安装工时";
        }
        model.addAttribute("dataSourceCode", abDataSource.getDataCode());
        model.addAttribute("title", title + "确认");
        return url;
    }

    /**
     * findTransport
     * 获取运费列表
     *
     * @param batId 单据表主键
     * @param dsId  数据源主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/12 19:57
     * @version 1.0
     */
    @ResponseBody
    @RequestMapping("/findTransport")
    public JsonResult findTransport(Integer batId, Integer dsId) {
        startPage();
        BusGeneralHoursModel param = new BusGeneralHoursModel();
        param.setBatId(batId);
        param.setDsId(dsId);

        BusBudgetAccountingTask busBudgetAccountingTask = getDataService.getBusBudgetAccountingTaskByPrimaryKey(batId);
        //设置是核算 还是预算 还是概算
        if (busBudgetAccountingTask.getTaskType() == 1) {
            param.setDataUseType(1);
        } else if (busBudgetAccountingTask.getTaskType() == 2) {
            param.setDataUseType(2);
        } else if (busBudgetAccountingTask.getTaskType() == 3) {
            param.setDataUseType(3);
        }
        BusDataSource dataSource = getDataService.getDataSourceByPrimaryKey(dsId);
        //获取专业
        String major = dataSource.getMajor();
        if ("机械".equals(major)) {
            param.setTypes("34");
        } else if ("流体".equals(major)) {
            param.setTypes("34");
        } else if ("自动化".equals(major)) {
            param.setTypes("34");
        }
        param.setMajor(major);
        param.setLaborTypes("17");
        param.setPart(dataSource.getPart());
        List<BusGeneralHoursModel> list = getDataService.findHours(param);
        return jsonResult(list);
    }

    @ResponseBody
    @RequestMapping("/findDesignHours")
    /**
     *  findDesignHours
     *  获取设计工时数据
     * @param [batId, dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 11:13
     * @version 1.0
     */
    public JsonResult findDesignHours(BusGeneralHoursModel param) {
        startPage();
        List<BusGeneralHoursModel> list = getDataService.findDesignHoursList(param);
        return jsonResult(list);
    }

    @ResponseBody
    @RequestMapping("/findWeightWeight")
    /**
     *  findDesignWeight
     *  获取设计重量数据
     * @param [batId, dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 11:21
     * @version 1.0
     */
    public JsonResult findDesignWeight(BusGeneralHoursModel param) {
        startPage();
        List<BusGeneralHoursModel> list = getDataService.findWeightWeightList(param);
        return jsonResult(list);
    }


    @ResponseBody
    @RequestMapping("/findBuyList")
    /**
     *  findBuyList
     *  根据数据源和单据表主键获取外购件列表
     * @param [batId, dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/23 18:13
     * @version 1.0
     */
    public JsonResult findBuyList(BusMaterialDataModel param) {
        startPage();
        List<BusMaterialDataModel> list = getDataService.findBuyList(param);
        return jsonResult(list);
    }

    @ResponseBody
    @PostMapping("/clearData")
    /**
     *  clearData
     *  清空指定数据源的数据
     * @param [dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 12:58
     * @version 1.0
     */
    public JsonResult clearData(BusGeneralHoursModel param) {
        return getDataService.clearData(param);
    }

    @ResponseBody
    @PostMapping("/clearMacData")
    /**
     *  clearMacData
     *  清空指定数据源的数据
     * @param [dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 12:58
     * @version 1.0
     */
    public JsonResult clearMacData(Integer dsId) {
        return getDataService.clearMacData(dsId);
    }

    @ResponseBody
    @PostMapping("/clearDataByMat")
    /**
     *  clearDataByMat
     *  清空材料
     * @param [dsId]
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/23 18:23
     * @version 1.0
     */
    public JsonResult clearDataByMat(BusMaterialDataModel param) {
        return getDataService.clearDataByMat(param);
    }


    /**
     * accountingDataSourceList
     * 获取核算数据源列表
     *
     * @param param 检索参数
     * @return JsonResult.data 数据
     * @author 徐一贺
     * @date 2020/9/16 19:14
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/accountingDataSourceList")
    public JsonResult accountingDataSourceList(AbDataSourceModel param) {
        return jsonResult(getDataService.findAccountingDataSourceList(param));
    }

    /**
     * accountingDataSourceList
     * 获取核算数据源列表
     *
     * @param param 检索参数
     * @return JsonResult.data 数据
     * @author 徐一贺
     * @date 2020/9/16 19:14
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/accountingDataSourceListByItem")
    public JsonResult accountingDataSourceListByItem(AbDataSourceModel param) {
        return jsonResult(getDataService.findAccountingDataSourceListByItem(param));
    }


    /**
     * list
     * 获取数据
     *
     * @param
     * @return 返回数据
     * @author 徐一贺
     * @date 2020/9/14 9:15
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/list")
    public JsonResult list() {
        startPage();
        List<GetMatDataModel> matDataModelList = getDataService.findList();
        return jsonResult(matDataModelList);
    }

//    /**
//     *  getMacColumns
//     *  获取动态列所需的数据
//     * @param [batId, dsId]
//     * @return com.zhongwang.business.common.JsonResult
//     * @author 徐一贺
//     * @date 2020/10/24 11:29
//     * @version 1.0
//     */
//    @ResponseBody
//    @PostMapping("/getMacColumns")
//    public JsonResult getMacColumns(Integer batId,Integer dsId){
//        BusBudgetAccountingTask busBudgetAccountingTask = getDataService.getBusBudgetAccountingTaskByPrimaryKey(batId);
//        BusDataSource dataSource = getDataService.getDataSourceByPrimaryKey(dsId);
//        //获取专业
//        String major = getDataService.getMajorFromBproductStructureByFkIdAndPartName(busBudgetAccountingTask.getProCode(), dataSource.getPart());
//        BusMachiningHoursModel macParam = new BusMachiningHoursModel();
//        macParam.setBatId(batId);
//        macParam.setDsId(dsId);
//        macParam.setProCode(busBudgetAccountingTask.getProCode());
//        if(busBudgetAccountingTask.getTaskType()==1){
//            macParam.setDataUseType(1);
//            macParam.setType(1);
//        }else if(busBudgetAccountingTask.getTaskType()==2){
//            macParam.setDataUseType(2);
//            macParam.setType(2);
//        }else if(busBudgetAccountingTask.getTaskType()==3){
//            macParam.setDataUseType(3);
//            macParam.setType(1);
//        }
//        macParam.setMajor(major);
//        macParam.setPart(dataSource.getPart());
//        return jsonResult(getDataService.getMacColumns(macParam));
//    }

    /**
     * findHours
     * 获取工时列表
     *
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/23 20:22
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/findHours")
    public JsonResult findHours(BusGeneralHoursModel param) {
        BusBudgetAccountingTask busBudgetAccountingTask = getDataService.getBusBudgetAccountingTaskByPrimaryKey(param.getBatId());
        //设置是核算 还是预算 还是概算
        if (busBudgetAccountingTask.getTaskType() == 1) {
            param.setDataUseType(1);
        } else if (busBudgetAccountingTask.getTaskType() == 2) {
            param.setDataUseType(2);
        } else if (busBudgetAccountingTask.getTaskType() == 3) {
            param.setDataUseType(3);
        }
        BusDataSource dataSource = getDataService.getDataSourceByPrimaryKey(param.getDsId());
        //获取专业
        String major = dataSource.getMajor();
        switch (dataSource.getDataCode()) {
            case "ds001":
                break;
            case "ds002":
                break;
            case "ds003":
                break;
            case "ds004":
                break;
            case "ds005":
                break;
            case "ds006":
                if ("机械".equals(major)) {
                    param.setTypes("7");
                } else if ("流体".equals(major)) {
                    param.setTypes("8");
                } else if ("自动化".equals(major)) {
                    param.setTypes("9");
                }
                param.setLaborTypes("4");
                break;
            case "ds007":
                if ("机械".equals(major)) {
                    param.setTypes("13");
                } else if ("流体".equals(major)) {
                    param.setTypes("14");
                } else if ("自动化".equals(major)) {
                    param.setTypes("15");
                }
                param.setLaborTypes("6");
                break;
            //机加 由于SQL语句是动态的所以查询结果类型也是动态的
            case "ds008":
                BusMachiningHoursModel macParam = new BusMachiningHoursModel();
                macParam.setBatId(param.getBatId());
                macParam.setDsId(param.getDsId());
                macParam.setProCode(busBudgetAccountingTask.getProCode());
                if (busBudgetAccountingTask.getTaskType() == 1) {
                    macParam.setDataUseType(1);
                    macParam.setType(1);
                } else if (busBudgetAccountingTask.getTaskType() == 2) {
                    macParam.setDataUseType(2);
                    macParam.setType(2);
                } else if (busBudgetAccountingTask.getTaskType() == 3) {
                    macParam.setDataUseType(3);
                    macParam.setType(1);
                }
                macParam.setMajor(major);
                macParam.setPart(dataSource.getPart());
                List<Map<String, String>> list = getDataService.findMacHours(macParam);
                return jsonResult(list);
            case "ds009":
                if ("机械".equals(major)) {
                    param.setTypes("19");
                } else if ("流体".equals(major)) {
                    param.setTypes("20");
                } else if ("自动化".equals(major)) {
                    param.setTypes("21");
                }
                param.setLaborTypes("8");
                break;
            case "ds010":
                if ("机械".equals(major)) {
                    param.setTypes("25");
                } else if ("流体".equals(major)) {
                    param.setTypes("26");
                } else if ("自动化".equals(major)) {
                    param.setTypes("27");
                }
                param.setLaborTypes("9,11");
                break;
            case "ds011":
                if ("机械".equals(major)) {
                    param.setTypes("31");
                } else if ("流体".equals(major)) {
                    param.setTypes("32");
                } else if ("自动化".equals(major)) {
                    param.setTypes("33");
                }
                param.setLaborTypes("13");
                break;
            case "ds012":
                param.setTypes("34");
                param.setLaborTypes("15");
                break;
            case "ds013":
                if ("机械".equals(major)) {
                    param.setTypes("38");
                } else if ("流体".equals(major)) {
                    param.setTypes("39");
                } else if ("自动化".equals(major)) {
                    param.setTypes("40");
                }
                param.setLaborTypes("18");
                break;
        }
//        param.setPart(dataSource.getPart());
        startPage();
        List<BusGeneralHoursModel> list = getDataService.findHours(param);
        return jsonResult(list);
    }

    /**
     * findMaterial
     * 获取辅材列表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/23 20:22
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/findMaterial")
    public JsonResult findMaterial(BusGeneralHoursModel param) {


        BusBudgetAccountingTask busBudgetAccountingTask = getDataService.getBusBudgetAccountingTaskByPrimaryKey(param.getBatId());
        //设置是核算 还是预算 还是概算
        if (busBudgetAccountingTask.getTaskType() == 1) {
            param.setDataUseType(1);
        } else if (busBudgetAccountingTask.getTaskType() == 2) {
            param.setDataUseType(2);
        } else if (busBudgetAccountingTask.getTaskType() == 3) {
            param.setDataUseType(3);
        }
        BusDataSource dataSource = getDataService.getDataSourceByPrimaryKey(param.getDsId());
        //获取专业
        String major = dataSource.getMajor();
        switch (dataSource.getDataCode()) {
            case "ds001":
                break;
            case "ds002":
                break;
            case "ds003":
                break;
            case "ds004":
                break;
            case "ds005":
                break;
            case "ds006":
                if ("机械".equals(major)) {
                    param.setTypes("7");
                } else if ("流体".equals(major)) {
                    param.setTypes("8");
                } else if ("自动化".equals(major)) {
                    param.setTypes("9");
                }
                param.setLaborTypes("5");
                break;
            case "ds007":
                if ("机械".equals(major)) {
                    param.setTypes("13");
                } else if ("流体".equals(major)) {
                    param.setTypes("14");
                } else if ("自动化".equals(major)) {
                    param.setTypes("15");
                }
                param.setLaborTypes("7");
                break;
            case "ds010":
                if ("机械".equals(major)) {
                    param.setTypes("25");
                } else if ("流体".equals(major)) {
                    param.setTypes("26");
                } else if ("自动化".equals(major)) {
                    param.setTypes("27");
                }
                param.setLaborTypes("10,12");
                break;
            case "ds011":
                if ("机械".equals(major)) {
                    param.setTypes("31");
                } else if ("流体".equals(major)) {
                    param.setTypes("32");
                } else if ("自动化".equals(major)) {
                    param.setTypes("33");
                }
                param.setLaborTypes("14");
                break;
            case "ds012":
                param.setTypes("34");
                param.setLaborTypes("16");
                break;
            case "ds013":
                if ("机械".equals(major)) {
                    param.setTypes("38");
                } else if ("流体".equals(major)) {
                    param.setTypes("39");
                } else if ("自动化".equals(major)) {
                    param.setTypes("40");
                }
                param.setLaborTypes("19");
                break;
        }
        param.setPart(dataSource.getPart());
        List<BusGeneralHoursModel> list = getDataService.findHours(param);
        return jsonResult(list);
    }

    /**
     * getMatData
     * 获取数据
     *
     * @param
     * @return
     * @author 徐一贺
     * @date 2020/9/14 9:51
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/getMatData")
    public JsonResult getMatData() {
        return getDataService.getMatData();
    }

    /**
     * getDataBySystem
     * 通过其他系统获取数据
     *
     * @param param 使用的参数
     * @return JsonResult 返回的结果
     * @author 徐一贺
     * @date 2020/9/17 19:41
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/getDataBySystem")
    @RequiresPermissions("ver:collection:aut")
    public JsonResult getDataBySystem(BusDataSourceModel param) {
        return getDataService.getDataBySystem(param);
    }


//    /**
//     * accountingDataList
//     * 获取对应任务对应数据源的数据
//     *
//     * @param
//     * @return
//     * @author 徐一贺
//     * @date 2020/9/18 11:19
//     * @version 1.0
//     */
//    @ResponseBody
//    @PostMapping("/accountingDataList")
//    public JsonResult accountingDataList(AbDataSourceModel param) {
//        startPage();
//        JsonResult result = new JsonResult();
//        BusDataSource abDataSource = getDataService.getAbDataSourceByPrimaryKey(param.getDsId().toString());
//        switch (abDataSource.getDataCode()) {
//            case "ds002":
//            case "ds003":
//            case "ds004":
////            case "ds005":
//                return jsonResult(getDataService.accountingDataListByMat(param));
//            case "ds008":
//                return jsonResult(getDataService.accountingDataListByMec(param));
//            default:
//                return jsonResult(getDataService.accountingDataListByGen(param));
//        }
//    }

    /**
     * updateDataStatus
     * 根据主键更改数据源状态
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/26 10:55
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/updateDataStatus")
    public JsonResult updateDataStatus(BusDataSourceModel param) {
        return getDataService.updateDataStatus(param);
    }

    /**
     * checkIsJump
     * 检测该项目下是否有产品结构
     *
     * @param code 项目号
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/30 13:56
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/checkIsJump")
    public JsonResult checkIsJump(String code) {
        return getDataService.checkPartIsExist(code);
    }

    /**
     * cancelSave
     * 取消保存
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/10 18:17
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/cancelSave")
    @RequiresPermissions("ver:adjust:view")
    public JsonResult cancelSave(BusBudgetAccountingTaskModel param) {
        return getDataService.cancelSave(param);
    }
    /**  restTask 重置并撤销任务
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @exception
     * @author 徐一贺
     * @date 2020/12/10 14:19
     */
    @ResponseBody
    @PostMapping("/restTask")
    @RequiresPermissions("ver:adjust:view")
    public JsonResult restTask(BusBudgetAccountingTaskModel param) {
        return getDataService.restTask(param);
    }

    /**
     * createCostSheet
     * 创建成本清单
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/11 11:01
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/createCostSheet")
    @RequiresPermissions("ver:adjust:view")
    public JsonResult createCostSheet(BusBudgetAccountingTaskModel param) {
        return getDataService.createCostSheet(param);
    }

    /**
     * revoke
     * 撤销创建成本清单
     *
     * @param batId 单据表主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/11 11:01
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/revoke")
    @RequiresPermissions("ver:adjust:view")
    public JsonResult revoke(Integer batId) {
        return getDataService.revoke(batId);
    }

    /**
     * revoke 根据组的ID获取对应组的成员列表，切不包含当前创建人
     *
     * @param groupId  组ID
     * @param userName 当前创建人
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/30 15:58
     */
    @ResponseBody
    @PostMapping("/getNewUserList")
    @RequiresPermissions("ver:adjust:view")
    public JsonResult getNewUserList(Integer groupId, String userName) {
        return jsonResult(getDataService.getNewUserList(groupId, userName));
    }

    /**
     * changeFounder 更换创建人
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/30 16:14
     */
    @ResponseBody
    @PostMapping("/changeFounder")
    @RequiresPermissions("ver:collec:change ")
    public JsonResult changeFounder(BusBudgetAccountingTaskModel param) {
        return getDataService.changeFounder(param);
    }

    /**  isPass 验证密码
     * @param password
     * @return com.zhongwang.business.common.JsonResult
     * @exception
     * @author 徐一贺
     * @date 2020/12/10 14:41
     */
    @ResponseBody
    @PostMapping("/isPass")
    public JsonResult isPass(String password) {
        JsonResult jsonResult = new JsonResult();
        try {
            User currentUser = ShiroUtils.getUser();
            UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(currentUser.getAccount(), password);
            Subject subject = SecurityUtils.getSubject();
            subject.login(usernamePasswordToken);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            return jsonResult;
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            return jsonResult;
        }
    }
}
